//
//  AccountInfoViewController.m
//  SDHuiYuShoping
//
//  Created by luojiao on 2017/6/22.
//  Copyright © 2017年 luojiao. All rights reserved.
//

#import "AccountInfoViewController.h"
#import "AccountInfoCell.h"
#import "ModifyPasswordVC.h"
#import "ModifyPhoneNumVC.h"
#import "HavePhoneNumVC.h"

@interface AccountInfoViewController ()
{
    NSArray *titleArr;
    NSArray *detailArr;
    NSArray *titleImageArr;
}

@property (nonatomic,assign) BOOL isCode;

@end

@implementation AccountInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置返回按钮
    [self.backButton setImage:[UIImage imageNamed:@"back_white_btn"] forState:UIControlStateNormal];
    [self.backButton setImageEdgeInsets:UIEdgeInsetsMake(0, -50, 0, 0)];
    [self.backButton setTitle:@"返回" forState:UIControlStateNormal];
    [self.backButton setTitleEdgeInsets:UIEdgeInsetsMake(0, -40, 0, 0)];
    
    
    titleArr = [[NSArray alloc] initWithObjects:@"登录密码",@"二级密码",@"手机验证", nil];
    detailArr = [[NSArray alloc] initWithObjects:@"建议定期更改密码以确保账户安全",@"建议定期更二级改密码以确保账户安全",@"若手机更换请尽快更改", nil];
    titleImageArr = [[NSArray alloc] initWithObjects:@"lock_logo",@"lock_logo",@"phone_logo", nil];
    
    _isCode = YES;
    self.tableView.separatorStyle = NO;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)backButton:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}



#pragma mark - UITableViewDelegate,UITableViewDataSource

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    AccountInfoCell *cell;
    
    static NSString *cellIdentifier = @"accountCell";
    cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell)
    {
        cell = [[NSBundle mainBundle] loadNibNamed:@"AccountInfoCell" owner:self options:nil][0];
    }
    
    cell.titleDetail.text = [detailArr objectAtIndex:indexPath.row];
    cell.title.text = [titleArr objectAtIndex:indexPath.row];
    cell.titleImage.image = [UIImage imageNamed:[titleImageArr objectAtIndex:indexPath.row] ];
    //cell 没有选中状态
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.row == 2)
    {
        cell.telNum.text = @"151****5442";
    }
    else
    {
        cell.telNum.hidden = YES;
    }
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0)
    {
        ModifyPasswordVC *modifyPasswordVC = [[ModifyPasswordVC alloc] init];
        modifyPasswordVC.titleStr = @"修改密码";
        [self.navigationController pushViewController:modifyPasswordVC animated:YES];
    }
    else if (indexPath.row == 1)
    {
        ModifyPasswordVC *modifyPasswordVC = [[ModifyPasswordVC alloc] init];
        modifyPasswordVC.titleStr = @"修改二级密码";
        [self.navigationController pushViewController:modifyPasswordVC animated:YES];
    }
    else if (indexPath.row == 2)
    {
        if (_isCode)
        {
            HavePhoneNumVC *havePhoneNumVC = [[HavePhoneNumVC alloc] init];
            [self.navigationController pushViewController:havePhoneNumVC animated:YES];
        }
        else
        {
            ModifyPhoneNumVC *modifyPhoneNum = [[ModifyPhoneNumVC alloc] init];
            modifyPhoneNum.titleName = @"手机验证";
            [self.navigationController pushViewController:modifyPhoneNum animated:YES];
        }
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
